<?php
class Core{
	private static $url = false;
	private static $req = false;
	private $area = false;


	/**
	* @var View
	*/
	private $view = false;
	
	function url()
	{
		return self::$url;
	}


	/**
	 * Enter description here...
	 * @return Request
	 */
	static function req()
	{
		return self::$req;
	}


	function __construct()
	{
		self::$url = new Url();
		self::$req = new Request(array_merge($_GET, $_POST), get_magic_quotes_gpc());
	}


	function  prepare($area = "visitor")
	{
		ob_get_clean();
		$this->area = $area;
	}


	function process()
	{
		$layout = "layout_".$this->area;
		
		if (!file_exists(_cfg("path")."/_inc/tpl/".$layout.".php"))
			$layout = "layout_default";
		$this->view = new View("tpl/".$layout);
		
		$default = _cfg("{$this->area}.default");
	
		$mod = $this->req()->get("mod", $default['mod']);
		$act = $this->req()->getAction($default['act']);
		
		$controller = Controller::factory($this->area, $mod, 'content');
		$view = $controller->process(self::$req);
		
		//$view = new View($alias);
		$view->setVar("area", $this->area);
		$view->setVar("mod", $mod);
		$view->setVar("req", $this->req());
		$view->setVar("act", $act);

		$this->view->setVar("html", $view->fetch(),0);
		$this->view->setVar("mod",$mod);
		$this->view->setVar("act",$act);
		
        echo $this->view->fetch();
        exit;
	}
}